package com.daikuan.fffkuaiban.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.daikuan.fffkuaiban.R;
import com.daikuan.fffkuaiban.bmobBean.ButtonConfigBean;
import com.daikuan.fffkuaiban.bmobBean.RecListBean;
import com.daikuan.fffkuaiban.utils.ImageLoader;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by jiming1 on 2017/7/1.
 */
public class HomeGridViewAdapter extends BaseAdapter {

	private Context context;
	private List<ButtonConfigBean> recListBeens;

	public HomeGridViewAdapter(Context context, List<ButtonConfigBean> recListBeens) {
		this.context = context;
		this.recListBeens = recListBeens;
	}

	@Override
	public int getCount() {
		return 4;
	}

	@Override
	public ButtonConfigBean getItem(int i) {
		return recListBeens.get(i);
	}

	@Override
	public long getItemId(int i) {
		return 0;
	}

	@Override
	public View getView(int i, View view, ViewGroup viewGroup) {
		BaseViewHolder viewHolder = null;
		final ButtonConfigBean recListBean = getItem(i);
		if (view == null) {
			view = LayoutInflater.from(context).inflate(R.layout.item_home_gridview, viewGroup, false);
			viewHolder = new BaseViewHolder(view);
			view.setTag(viewHolder);
		} else {
			viewHolder = (BaseViewHolder) view.getTag();
		}

		if (recListBean.type_logo == null) {
			ImageLoader.loadImage(context, "", viewHolder.imageView);
		} else {
			ImageLoader.loadImage(context, recListBean.type_logo.url, viewHolder.imageView);
		}
		viewHolder.tvName.setText(recListBean.type_name);
		return view;
	}


	class BaseViewHolder {
		@Bind(R.id.imageView)
		ImageView imageView;
		@Bind(R.id.tvName)
		TextView tvName;

		public BaseViewHolder(View view) {
			ButterKnife.bind(this, view);
		}
	}


}
